package t2dao;

import java.util.List;

import t2bean.BookBean;
import t2bean.CardBean;
import t2bean.LendBookRecordBean;

public class SetSql {
	public String setSql(BookBean book, String sql, List<Object> list, int m) {
		int n = 0;
		if (book.getBookId() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "bookid=?";
			list.add(book.getBookId());
			n = m;
		}
		if (book.getName() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "name=?";
			list.add(book.getName());
			n = m;
		}
		if (book.getIsLended() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "islended=?";
			list.add(book.getIsLended());
			n = m;
		}
		if (book.getLendTimes() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += "and";
			}
			sql += "lendtimes=?";
			list.add(book.getLendTimes());
			n = m;
		}
//		System.out.println(sql);
		return sql;
	}

	public String setSql(CardBean card, String sql, List<Object> list, int m) {
		int n = 0;
		if (card.getCardId() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "cardid=?";
			list.add(card.getCardId());
			n = m;
		}
		if (card.getName() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "name=?";
			list.add(card.getName());
			n = m;
		}
		return sql;
	}

	public String setSql(LendBookRecordBean lend, String sql, List<Object> list, int m) {
		int n = 0;
		if (lend.getBookId() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "bookid=?";
			list.add(lend.getBookId());
			n = m;
		}
		if (lend.getCardId() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "cardid=?";
			list.add(lend.getCardId());
			n = m;
		}
		return sql;
	}
}
